package org.zcl.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.zcl.entity.model.ApiResponse;
import org.zcl.entity.po.TbUserInfo;
import org.zcl.entity.po.User;
import org.zcl.entity.response.UserVO;
import org.zcl.service.TbUserInfoService;


/**
 * 模拟控制器
 *
 * @author zhuchenglin
 * @date 2022/09/07 11:15
 * @since 2022/9/7 11:13
 */
@Api(value = "/mock/", tags = {"模拟控制器"})
@RestController
@RequiredArgsConstructor
@RequestMapping("/mock/")
@PropertySource(value = {"classpath:mock.properties"})
@Slf4j
public class MockController extends BaseAction {

    @Value("${mock.name}")
    private String name;

    private final User user;

    @NonNull
    private TbUserInfoService tbUserInfoService;

    /**
     * 获取用户
     *
     * @param id id
     * @return {@link ApiResponse}<{@link TbUserInfo}>
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "long", name = "id", value = "id")
    })
    @ApiOperation(value = "获取用户", notes = "获取用户")
    @GetMapping("name")
    public ApiResponse<UserVO> getUser(@RequestParam Long id) {
        log.info("data:{}", JSON.toJSONString(user));
        UserVO userVO = tbUserInfoService.selectUserById(id);
        userVO.setName(name);
        return returnSuccess(userVO);
    }
}
